import { _decorator, Component, Label, Node } from 'cc';
import { GameManager } from '../GameManager';
import { CARDPROBABILITY } from '../../AshFramework/Datas/GameConstant';
const { ccclass, property } = _decorator;

@ccclass('ProbabilityWindow')
export class ProbabilityWindow extends Component {
    private static _instance: ProbabilityWindow = null;
    public static get Instance(): ProbabilityWindow {
        if (!ProbabilityWindow._instance) {
            ProbabilityWindow._instance = new ProbabilityWindow();
        }
        return ProbabilityWindow._instance
    }
    @property(Label)
    GradeLabel: Label = null;

    @property(Label)
    probabalityLabel_1: Label = null;

    @property(Label)
    probabalityLabel_2: Label = null;

    @property(Label)
    probabalityLabel_3: Label = null;

    @property(Label)
    probabalityLabel_4: Label = null;

    public probability1: number = 0;
    public probability2: number = 0;
    public probability3: number = 0;
    public probability4: number = 0;

    protected onLoad(): void {
        ProbabilityWindow._instance = this;
    }

    updateProbability() {
        let grade = GameManager.Instance.userData.drawCardGrade;
        this.probability2 = CARDPROBABILITY.CARD_BLUE * (grade - 1);
        this.probability3 = CARDPROBABILITY.CARD_PURPLE * (grade - 1);
        this.probability4 = CARDPROBABILITY.CARD_GOLDEN * (grade - 1);
        this.probability1 = 100 - this.probability2 - this.probability3 - this.probability4;
    }

    showProbability() {
        let grade = GameManager.Instance.userData.drawCardGrade;
        this.GradeLabel.string = String(grade);
        this.probabalityLabel_1.string = String(this.probability1);
        this.probabalityLabel_2.string = String(this.probability2);
        this.probabalityLabel_3.string = String(this.probability3);
        this.probabalityLabel_4.string = String(this.probability4);
    }

    protected onEnable(): void {
        this.updateProbability();
        this.showProbability();
    }
}


